Some scRNA and scTCR tumor timepoints were relabelled after this analysis was conducted. These are the corrected timepoints: 101: W20 -> W24 103: W20 -> W25
2.1 Set up workspace
# Load librarieslibrary(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(Seurat)
Loading required package: SeuratObject
Loading required package: sp
Attaching package: 'SeuratObject'
The following objects are masked from 'package:base':
intersect, t
library(dplyr)library(scRepertoire)
Functions to create the custom definition of clones
# Turn all entries of c_gene into ""to_empty <-function(df){ df$c_gene <-""return(df)}# Count number of TRA and TRB per barcodecount_TRA_TRB <-function(df){ df <- df %>%mutate(TCR1_count =str_count(TCR1, fixed(";")) +1,TCR2_count =str_count(TCR2, fixed(";")) +1,TCR1_count =replace_na(TCR1_count, 0),TCR2_count =replace_na(TCR2_count, 0))}# Remove the barcode if it has 2A+2B or 3A/XB or XA/3Bremove_multi_chains <-function(df){ df <- df %>%# 2A+2Bfilter(!(TCR1_count ==2& TCR2_count ==2),!(TCR1_count >=3),!(TCR2_count >=3))}# Remove "NA" if it was supposed to be the "C" gene in TRArm_na_TCR1 <-function(df){ df <- df %>%mutate(TCR1 =str_replace_all(TCR1, "(\\.NA(?=;))|(\\.NA$)", ""))return(df)}# Remove "NA" if it was supposed to be the "C" or "D" gene in TRB (D gene is not seen in bulkTCR data anyway)rm_na_TCR2 <-function(df){ df <- df %>%mutate(TCR2 =str_replace_all(TCR2, "(\\.NA(?=;))|(\\.NA(?=.))|(\\.NA$)", ""))return(df)}# Create new columns: CTVJaa, CTbeta, CTalphacreate_columns <-function(df){ df <- df %>%mutate(vjaa =paste0(TCR1, ";", cdr3_aa1, "_", TCR2, ";", cdr3_aa2),alpha =paste0(TCR1, ";", cdr3_aa1),beta =paste0(TCR2, ";", cdr3_aa2))}